import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [{
        path: '/',
        redirect: '/guide'
    },
    {
        path: "/mine",
        name: "mine",
        component: () =>
            import ('@/views/mine/mine.vue')
    },
    {
        path: "/guide",
        name: "guide",
        component: () =>
            import ('@/views/guide/guide.vue')
    },
    {
        path: "/login",
        name: "login",
        component: () =>
            import ('@/views/login/login.vue')
    },
    {
        path: "/shoucang",
        name: "shoucang",
        component: () =>
            import ('@/views/shoucang/shoucang.vue')
    },
    {
        path: "/pinglun",
        name: "pinglun",
        component: () =>
            import ('@/views/pinglun/pinglun.vue')
    },
    {
        path: "/register",
        name: "register",
        component: () =>
            import ('@/views/login/register.vue')
    },
    {
        path: "/online",
        name: "online",
        component: () =>
            import ('@/views/online/online.vue')
    },
    {
        path: "/listen",
        name: "listen",
        component: () =>
            import ('@/views/listen/listen.vue'),
        redirect: "/listen/index",
        children: [{
                path: "index",
                name: "index",
                component: () =>
                    import ('@/views/index/index.vue')
            },
            {
                path: "fenLei",
                name: "fenLei",
                component: () =>
                    import ('@/views/fenLei/fenLei.vue')
            },
            {
                path: "detail",
                name: "detail",
                component: () =>
                    import ('@/views/detail/detail.vue')
            },
            {
                path: "sousuo",
                name: "sousuo",
                component: () =>
                    import ('@/views/sousuo/sousuo.vue')
            },


        ]
    },
    {
        path: "*",
        redirect: {
            name: 'listen'
        }
    },
]

// router.beforeEach((to, from, next) => {
//     // var cityInfo = localStorage.getItem('cityInfo');
//     // cityInfo = cityInfo ? JSON.parse(cityInfo) : cityInfo;

//     // 添加时间戳  

//     if (to.name == "mine" || to.name == 'index') {
//         // 判断 
//         // next();
//         if (typeof to.query._t !== "undefined") {
//             next();
//         } else {
//             to.query._t = new Date().getTime().toString();
//             next(to);
//         }
//     }


// })

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

const router = new VueRouter({
    mode: 'hash',
    base: process.env.BASE_URL,
    routes
})

export default router